#include<iostream>
#include<algorithm>

using namespace std;

// 打印矩阵
void printMatrixInCircle(int ** matrix, int rows, int cols, int start){
    if ( matrix == nullptr || rows<=0 || cols <= 0 )
        return;
    // 定义起始打印位置（start, start）
    // 定义右下角打印位置 (endRow, endCol)
    int endRow = rows - start - 1;
    int endCol = cols - start - 1;

    // 打印第一行
    for ( int i = start ; i <= endCol; i++ ){
        cout << "打印第一行" << matrix[start][i] << "  " << endl;
    }

    if ( start <= endCol ){
        // 打印最后一列 
        for ( int i = start+1; i <= endRow ; i++ ){
            cout << "打印最后一列" <<  matrix[i][endCol] << "  " << endl;
        }
    }
    if ( start < endRow && start< endCol ){
        // 打印最后行
        for ( int i = endCol-1; i >=start ; i-- ){
            cout << "打印最后行" << matrix[endRow][i] << "  " << endl;
        }
    }
    if ( start < endCol && start < endRow-1  ){
        // 打印第一列
        for ( int i = endRow-1; i >start ; i-- ){
            cout <<"打印最后一列" <<  matrix[i][start] << "  " << endl;
        }
    }
}

void printMatrix(int ** data, int rows, int cols){
	for ( int row = 0; row<rows; row++ ){
        for ( int col = 0; col < cols; col++ ){
            cout << data[row][col] << "  " ;
        }
        cout << endl;
    }
}

// 判断矩阵所属Case
void printMatrixWisely(int ** matrix, int rows, int cols){
    if ( matrix == nullptr || rows <= 0 || cols <= 0 )
        return;
    int start = 0;
    while ( ( min(rows, cols) + min(rows, cols)%2 ) > start * 2 ){
        printMatrixInCircle(matrix, rows, cols, start);
        start ++;
    }
}

void createMatrix(int rows, int cols){
    if ( rows <= 0 || cols <= 0 )
        return;
    int ** matrix =  new int*[rows];
    for ( int row=0; row < rows; row ++ ){
        matrix[row] = new int[cols];
        for ( int col = 0; col< cols; col++ ){
            matrix[row][col] = row*cols+col+1;
        }
    }

    printMatrix(matrix, rows, cols);

    printMatrixWisely(matrix, rows, cols);

    delete[] matrix;
}

int main(void){
    createMatrix(1,1);
	return 0;
}